﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.DTOs.SectionDto;
using static Butcher.winform.EnterpriseForms.Departmentview;

namespace Butcher.winform.EnterpriseForms
{
    public partial class SlaughteredDetailes : Form
    {
        public SlaughteredDetailes()
        {
            InitializeComponent();
            string url = @"http://localhost:5229/api/Section/SectionHtml";
            HttpClient client = new HttpClient();
            QueryCondition condition = new QueryCondition();
            condition.pageindex = 1;
            condition.pagesize = 2;
            condition.sectionName = "";
            condition.sectionType = 0;
            condition.sectionStatus = 0;
            var content = new StringContent(JsonSerializer.Serialize<QueryCondition>(condition), Encoding.UTF8);
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject josnresult = JObject.Parse(result);
            var results = josnresult["neWsections"].Value<JArray>();
            List<NEWsection> ssss = results.ToObject<List<NEWsection>>();
            this.cb_Level.DataSource = ssss;
            this.cb_Level.DisplayMember = "DepartmentName";
            this.cb_Level.ValueMember = "Departmentid";
        }

        private void button_Click(object sender, EventArgs e)
        {
            SlaughterCircle circle = new SlaughterCircle();
            if (rb_State1.Checked)
            {
                circle.SlaughterCircledType = rb_State1.Text;
            }
            if (rb_State2.Checked)
            {
                circle.SlaughterCircledType = rb_State2.Text;
            }
            circle.SlaughterCircleName= textBox4.Text;
            circle.Departmentid =Convert.ToInt32(cb_Level.SelectedValue);
            circle.Head = textBox2.Text;
            circle.Remark = textBox1.Text;
            
            string url = @"http://localhost:5229/api/Section/WaitingCircleCteate";
            HttpClient client = new HttpClient();
            var content = new StringContent(JsonSerializer.Serialize<SlaughterCircle>(circle));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            if(info != null)
            {
                MessageBox.Show("新增成功");
            }
            else
            {
                MessageBox.Show("新增失败");
            }
        }
    }
}
